package com.onlyMe.world.path
{
	import com.onlyMe.geom.Coord;
	import com.onlyMe.world.tiling.Tile;
	import com.onlyMe.world.tiling.TileGrid;

	public class TileGridPathMap implements PathFinderMap
	{
		private var grid:TileGrid;
		
		public function TileGridPathMap(grid:TileGrid)
		{
			this.grid = grid;
		}
		
		public function isBlocked(dest:Coord):Boolean
		{
			var tile:Tile = grid.getTileAtCoord(dest);
			return !tile || tile.blocked || tile.blockedByChildren;
		}
		
		public function getCost(orig:Coord, dest:Coord):Number
		{
			if (orig.x === dest.x || orig.y === dest.y)
				return 1;

			return Math.SQRT2;
		}
		
		public function getEstimatedCost(orig:Coord, dest:Coord):Number
		{
			return Math.abs(orig.x - dest.x) + Math.abs(orig.y - dest.y);
		}
		
	}
}
